package com.atguigu.controller;

import com.atguigu.dto.system.AssginMenuDto;
import com.atguigu.dto.system.SysMenuDto;
import com.atguigu.entity.system.SysMenu;
import com.atguigu.service.SysMenuService;
import com.atguigu.vo.common.Result;
import com.atguigu.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "菜单管理")
@RestController
@RequestMapping("/system/menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    // 新增菜单
    @Operation(summary = "新增菜单")
    @PostMapping("/submit")
    public Result submit(@RequestBody SysMenu sysMenu) {
        sysMenuService.submit(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    // 删除菜单
    @Operation(summary = "删除菜单")
    @GetMapping("/remove")
    public Result remove(@RequestParam Long menuId) {
        sysMenuService.remove(menuId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    // 修改菜单
    @Operation(summary = "修改菜单")
    @PostMapping("/update")
    public Result update(@RequestBody SysMenu sysMenu) {
        sysMenuService.update(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    // 查询菜单树
    @Operation(summary = "查询菜单树")
    @GetMapping("/tree")
    public Result tree(@RequestParam(required = false) SysMenuDto sysMenuDto) {
        List<SysMenu> treeMenuList = sysMenuService.tree(sysMenuDto);
        return Result.build(treeMenuList, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "用户菜单列表")
    @GetMapping("/menus")
    public Result menus() {
        List<SysMenu> menuList = sysMenuService.menus();
        return Result.build(menuList,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "通过权限id查询权限菜单id")
    @GetMapping("/roleMenus")
    public Result roleMenus(@RequestParam Long roleId) {
        List<Long> roleMenuMap = sysMenuService.roleMenus(roleId);
        return Result.build(roleMenuMap,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加权限菜单")
    @PostMapping("/addRoleMenus")
    public Result addRoleMenus(@RequestBody AssginMenuDto assginMenuDto) {
        sysMenuService.addRoleMenus(assginMenuDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
